/**
 * Copyright (C)  Gadglet .
 *
 * This file is part of Gadglet
 *
 * Gadglet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gadglet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gadglet.client.gwt.core.ui;

import com.gadglet.client.gwt.GadgetUtils;
import com.gadglet.client.gwt.ui.DebugDialogBox;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.gadgets.client.impl.PreferencesUtil;
import com.google.gwt.user.client.ui.Image;

public class ShareWithIcon extends Image{

	final private String itemId;
	private Image icon;
	final private String itemTitle;
	
	final PreferencesUtil prefs = PreferencesUtil.nativeInitPrefs();
	private DebugDialogBox debug = DebugDialogBox.getErrorNotifier();
	
	public ShareWithIcon (String id, String title){
		icon = new Image(GadgetUtils.getIconURL("shareWith", null, false));
		icon.setTitle(prefs.getMsg("gadgetLabelShare"));
		itemId= id;
		
			
		if(title!=null && title.length()>44)
				title = title.substring(0, 40)+"...";
				
		itemTitle = title;
		
		icon.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {
				ShareWithDialogPanel panel = ShareWithDialogPanel.getShareWithDialogPanel();
				panel.showShareWithDialogPanel(itemId,itemTitle);

			}

		});
	}

	
	public Image getImage(){

	
		return icon;
	}
	
	
	
}
